/**   
 * @Title: WebViewActivity.java 
 * @Package: com.esun.rabbit2.viewer 
 * @Description: 通用webView Activity
 * @Author: Miko baoz@500wan.com   
 * @Date: 2011-7-5 下午04:37:15  
 * Copyright (C) 2011 Shenzhen E-sun Sky Net Technology Co.,ltd.
 */
package com.esun.rabbit2.viewer;

import com.esun.network.ConnectionChangeReceiver;
import com.esun.ui.R;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageButton;
import android.widget.TextView;

/**
 * @ClassName: WebViewActivity
 * @Description: 通用webView Activity 需要传入 url参数 以及页面title
 * @Author: Miko baoz@500wan.com
 * @Date: 2011-7-5 下午04:37:15
 * 
 */
public class WebViewActivity extends Activity implements OnClickListener {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.common_web_act);

		Intent intent = getIntent();

		String url = intent.getStringExtra("url");
		String title = intent.getStringExtra("title");

		((TextView) this.findViewById(R.id.common_web_act_tv_title)).setText(title);

		((ImageButton) this.findViewById(R.id.common_web_act_btn_goBack)).setOnClickListener(this);

		final View progress = (View) this.findViewById(R.id.common_web_act_progress);

		WebView web = (WebView) this.findViewById(R.id.commen_web_web);
		web.getSettings().setJavaScriptEnabled(true);
		web.setBackgroundColor(0);
		web.setWebViewClient(new WebViewClient() {

			@Override
			public void onPageFinished(WebView view, String url) {
				super.onPageFinished(view, url);

				progress.setVisibility(View.GONE);

			}

			@Override
			public void onPageStarted(WebView view, String url, Bitmap favicon) {
				super.onPageStarted(view, url, favicon);

				progress.setVisibility(View.VISIBLE);

			}
		});
		web.loadUrl(url);
	}

	@Override
	public void onClick(View v) {
		this.finish();
	}

	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		this.unregisterReceiver(ConnectionChangeReceiver.getConnectionChangeReceiver());
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		this.registerReceiver(ConnectionChangeReceiver.getConnectionChangeReceiver(), ConnectionChangeReceiver.getIntentFilter());
	}
}
